package previous.Test_0321;

import java.util.*;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
public class Bridge_Blue {
    //特别数的和
    //2,0,1,9
    public static void main1(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n=scan.nextInt();
        long sum=0;
        for (int i = 0; i <=n; i++) {
            if(pan(i)){
                sum+=i;
            }
        }
        System.out.println(sum);
        scan.close();
    }
    public static boolean pan(int n){
        String tmp=String.valueOf(n);
        if(tmp.contains("0") || tmp.contains("1") || tmp.contains("2") || tmp.contains("9")){
            return true;
        }
        return false;
    }
    //外卖优先级
    //大于5，进入优先级
    //小于等于3，退出优先级
    //没有订单-1
    //有+2
    public static void main2(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n=scan.nextInt();
        int m=scan.nextInt();
        int t=scan.nextInt();
        Map<Integer,Integer> hash1=new HashMap<>();
        int[][] p=new int[m][2];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < 2; j++) {
                p[i][j]=scan.nextInt();
                hash1.put(p[i][1],hash1.getOrDefault(p[i][1],0)+1);
            }
        }
        List<Integer> list=new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int sum=0;
            int dt=t-hash1.get(i);
            sum=hash1.get(i)*2-dt;
            if(sum>5) list.add(i);
        }
        System.out.println(list.size());
        scan.close();
    }
    //人物相关性分析
    public static void main3(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int k=scan.nextInt();
        scan.nextLine();
        String s=scan.nextLine();
        List<Integer> a=new ArrayList<>();
        List<Integer> b=new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            StringBuilder al=new StringBuilder();
            StringBuilder bo=new StringBuilder();
            if(i+5<=s.length() && s.substring(i,i+5).equals("Alice")){
                a.add(i);
            }
            if(i+3<=s.length() && s.substring(i,i+3).equals("Bob")){
                b.add(i);
            }
        }
        int count=0;
        for (int i:a) {
            for (int j:b) {
                if(Math.abs(i-j)<=k+5){
                    count++;
                }
            }
        }
        System.out.println(count);
        scan.close();
    }
    //题解100%
    static String s;
    public static void main0(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        sc.nextLine();//去除多余的回车符号
        s = sc.nextLine();//输入字符串
        ArrayList<Integer> alice = new ArrayList<>();//存放Alice的位置
        ArrayList<Integer> bob = new ArrayList<>();//存放Bob的位置
        for (int i = 0; i < s.length(); i++) {//寻找Alice和Bob出现的位置
            if (i + 5 <= s.length() &&
             s.substring(i, i + 5).equals("Alice") && check(5, i))
                alice.add(i);
            if (i + 3 <= s.length() &&
            s.substring(i, i + 3).equals("Bob") && check(3, i))
                bob.add(i);
        }
        int l = 0, r = 0;//左右指针
        long ans = 0;//最后结果
        for (int i = 0; i < alice.size(); i++) {
            //获取Alice的索引  k<alice-3-bob  bob-alice-5<k
            int index = alice.get(i);
            //bob在Alice左边
            while (l < bob.size() && bob.get(l) < index - k - 3) l++;
            //bob在Alice右边
            while (r < bob.size() && bob.get(r) < index + k + 5) r++;
            ans += r - l;//右-左=共同出现的次数
        }
        System.out.println(ans);
    }

    public static boolean check(int k, int i) {//判断i前后是否有字母 防止出现xxAlicexx
        if (i + k < s.length()) {//如果右指针没有超过字符串长度
            //判断i后面是否有字母
            if (s.charAt(i + k) >= 'A' && s.charAt(i + k) <= 'Z')
                return false;
            if (s.charAt(i + k) >= 'a' && s.charAt(i + k) <= 'z')
                return false;
        }
        if (i - 1 >= 0) {//判断i前面是否有字母
            if (s.charAt(i - 1) >= 'A' && s.charAt(i - 1) <= 'Z')
                return false;
            if (s.charAt(i - 1) >= 'a' && s.charAt(i - 1) <= 'z')
                return false;
        }
        return true;
    }


    // 迷宫
    public static void main4(String[] args) {
        Scanner scan = new Scanner(System.in);
        int[][] num=new int[30][50];
        for (int i = 0; i < 30; i++) {
            String line = scan.nextLine();
            for (int j = 0; j < 50; j++) {
                num[i][j] = line.charAt(j)-'0';
            }
        }
        String[][] path=new String[30][50];
        boolean[][] vis=new boolean[30][50];
        path[0][0]="";
        String[] s={"D", "L", "R", "U"};
        Queue<int[]> q=new LinkedList<>();
        q.add(new int[]{0,0});
        long step=0;
        int[] dx = {1, 0, 0, -1}; // 下、左、右、上
        int[] dy = {0, -1, 1, 0};
        while(!q.isEmpty()){
            int[] t=q.poll();
            int a=t[0];
            int b=t[1];
            step++;
            if(a==29 && b==49) {
                System.out.println(path[a][b]);
                return;
            }
            vis[a][b]=true;
            for (int j = 0; j < 4; j++) {
                int x=dx[j]+a;
                int y=dy[j]+b;
                if(x>=0 && x<30 && y>=0 && y<50 && !vis[x][y] && num[x][y]!=1){
                    q.add(new int[]{x,y});
                    path[x][y]=path[a][b]+s[j];
                    vis[x][y]=true;
                }

            }
        }
        //在此输入您的代码...
        scan.close();
    }
    static int m;
    static int n;
    public static void main6(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
         n=scan.nextInt();
         m=scan.nextInt();
        long[] num=new long[m+n+1];
        for (int i = 0; i < m+n+1; i++) {
            num[i]=scan.nextInt();
        }
        long ret=0;
        ret=Math.max(dfs(num,0,0,0,num[0]),ret);
        System.out.println(ret);
        scan.close();
    }
    public static long dfs(long[] num,int step,long x,long y,long sum){
        if(step==m+n+1){
            return sum;
        }
        long max=sum;
        if(x<m){
            max=Math.max(dfs(num,step+1,x+1,y,sum+num[step+1]),sum);
        }
        if(y<n){
            max=Math.max(dfs(num,step+1,x,y+1,sum-num[step+1]),sum);
        }
        return max;
    }
    //贪心
    //后缀表达式
    public static void main7(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n=scan.nextInt();
        int m=scan.nextInt();
        long[] num=new long[(m+n+1)];
        for (int i = 0; i < m+n+1; i++) {
            num[i]=scan.nextInt();
        }
        Arrays.sort(num);
        long sum=0;
        if(m==0){
            for (int i = 0; i < n+m+1; i++) {
                sum+=num[i];
            }
        }else{
            sum=num[n+m]-num[0];
            for (int i = 1; i <m+n ; i++) {
                sum+=Math.abs(num[i]);
            }
        }
        System.out.println(sum);
        scan.close();
    }
    //门牌制作
    public static void main9(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int count=0;
        for (int i = 0; i <= 2020; i++) {
            String tmp=String.valueOf(i);
            if(tmp.contains("2")){
                count+=getM(tmp);
            }
        }
        System.out.println(count);
        scan.close();
    }
    public static int getM(String n){
        int count=0;
        char[] c=n.toCharArray();
        for (int i = 0; i < c.length; i++) {
            if(c[i]=='2'){
                count++;
            }
        }
        return count;
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int sum=1;
        for (int i = 1; i <=20 ; i++) {
            sum+=(i-1)*4;
        }
        scan.close();
    }
}
